package com.qianyu.project.mapper.provider.zxm;

import com.qianyu.project.entity.SecurityLog;
import org.apache.ibatis.jdbc.SQL;
/**
 * @author zxm
 * @date 2021/2/2 16:08
 */
public class SecurityLogProvider {
    public  String getSecurityLogList(SecurityLog sl){
        return  new SQL(){
            {
                SELECT("*");
                FROM("security_log sl,project_info pf,system_user su,dept d");
                WHERE("sl.fill_user=su.id and sl.dept_id=d.id and sl.p_id=pf.id");
                if(sl.getSecuritySituation()!=null){
                    WHERE("sl.security_situation like '%"+sl.getSecuritySituation()+"%'");
                }
                if(sl.getPId()!=null){
                    WHERE("sl.p_id = '"+sl.getPId()+"'");
                }
                if(sl.getDeptId()!=null){
                    WHERE("sl.dept_id = '"+sl.getDeptId()+"'");
                }
                if(sl.getUpdateDate()!=null){
                    WHERE("sl.update_date like '%"+sl.getUpdateDate()+"%'");
                }
                if(sl.getFillUser()!=null){
                    WHERE("sl.fill_user = '"+sl.getFillUser()+"'");
                }
                if(sl.getId()!=null){
                    WHERE("sl.id like '%"+sl.getId()+"%'");
                }
                if(sl.getWorkPart()!=null){
                    WHERE("sl.work_part like '%"+sl.getWorkPart()+"%'");
                }
                if(sl.getApproveStatus()!=null){
                    WHERE("sl.approve_status like '%"+sl.getApproveStatus()+"%'");
                }
            }
        }.toString();
    }
    public String getProjectName(){
        return  new SQL(){
            {
                SELECT("*");
                FROM("project_info");
            }
        }.toString();
    }
    public String getDeptName(){
        return  new SQL(){
            {
                SELECT("*");
                FROM("dept");
            }
        }.toString();
    }
    public String getUserName(){
        return  new SQL(){
            {
                SELECT("*");
                FROM("system_user");
            }
        }.toString();
    }
    public String deleteSecurityLogId(String id){
        return  new SQL(){
            {
                DELETE_FROM("security_log");
                WHERE("id='"+id+"'");
            }
        }.toString();
    }
    public String getSecurityLogId(String id){
        return  new SQL(){
            {
                SELECT("*");
                FROM("security_log sl,project_info pf,system_user su,dept d");
                WHERE("sl.fill_user=su.id and sl.dept_id=d.id and sl.p_id=pf.id and sl.id='"+id+"'");
            }
        }.toString();
    }
    public String addSecurityLog(SecurityLog ss){
        return  new SQL(){
            {
                INSERT_INTO("security_log");
                INTO_VALUES("null","#{pId}","#{flowId}","#{fillUser}","#{workerCount}","#{deptId}","#{temperature}","#{updateDate}","#{workPart}","#{securitySituation}","#{securityEduation}","#{securityDisclosure}","#{acceptRecord}","#{securityCheck}","#{securityMeetingRecord}","#{other}","#{approveStatus}");
            }
        }.toString();
    }
    public String updateSecurityLog(SecurityLog sl){
        return  new SQL(){
            {
                UPDATE("security_log");
                SET("p_id='"+sl.getPId()+"',fill_user='"+sl.getFillUser()+"',dept_id='"+sl.getDeptId()+"',update_date='"+sl.getUpdateDate()+"',work_part='"+sl.getWorkPart()+"',security_situation='"+sl.getSecuritySituation()+"',approve_status='"+sl.getApproveStatus()+"'");
                WHERE("id='"+sl.getId()+"'");
            }
        }.toString();
    }
}
